<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dept">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.title"
            placeholder="活动名称/地点/内容"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.islandId"
            placeholder="所属区域"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in scenicOptions"
              :key="item.id"
              :label="item.scenicName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="dataForm.time"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('scenic:commactivity:save')"
            type="primary"
            @click="addOrUpdateHandle()"
            >{{ $t("add") }}</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
		:height="he"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="title"
          label="活动名称"
          header-align="center"
          align="center"
          :show-overflow-tooltip="true"
          min-width="120"
        ></el-table-column>
        <el-table-column
          prop="activityType"
          label="活动类型"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            {{ $getDictLabel("activityType", scope.row.activityType) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          header-align="center"
          align="center"
          min-width="150"
        >
        </el-table-column>
        <el-table-column
          prop="islandName"
          label="所属区域"
          header-align="center"
          align="center"
          min-width="150"
        >
        </el-table-column>
        <el-table-column
          prop="address"
          label="活动地址"
          header-align="center"
          align="center"
          min-width="150"
        >
        </el-table-column>
        <!-- <el-table-column prop="num" label="已报名人数" header-align="center" align="center" min-width="150">
            </el-table-column> -->
        <el-table-column
          prop="startTime"
          label="活动开始时间"
          header-align="center"
          align="center"
          min-width="150"
        ></el-table-column>
        <el-table-column
          prop="endTime"
          label="活动结束时间"
          header-align="center"
          align="center"
          min-width="150"
        ></el-table-column>
        <el-table-column
          prop="pic"
          label="封面"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-image
              :src="scope.row.pic"
              style="width: 100px; height: 100px"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="230"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              v-if="
                $hasPermission('scenic:commapplication:page') &&
                scope.row.isApplication == 1
              "
              @click="lookRecord(scope.row.id, scope.row.title)"
              >查看报名记录</el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('scenic:commactivity:update')"
              @click="addOrUpdateHandle(scope.row.id)"
              >编辑</el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('scenic:commactivity:getOne')"
              @click="lookDetail(scope.row.id)"
              >详情</el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('scenic:commactivity:delete')"
              @click="deleteHandle(scope.row.id)"
              >{{ $t("delete") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></add-or-update>
      <!-- 详情 -->
      <detail ref="lookDetail" v-if="lookDetailVisible"> </detail>
      <!-- 报名记录 -->
      <el-drawer :title="title" :visible.sync="lookShow" size="50%">
        <list ref="lookRecord"></list>
      </el-drawer>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./notice-add-or-update";
import detail from "./detail";
import list from "../registration/index";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/scenic/commactivity/getPage",
        deleteURL: "/scenic/commactivity",
        getDataListIsPage: true,
        deleteIsBatch: true,
        // exportURL: "/scenic/commactivity/export",
      },
	  he:'auto',
      title: "",
      lookShow: false,
      scenicOptions: [],
      dataForm: {
        title: "",
        islandId: "",
        time: "",
      },
    };
  },
  components: {
    AddOrUpdate,
    detail,
    list,
  },
  watch:{
	dataList(newval, oldval) {
      if (newval != oldval) {
        this.he = "auto";
        setTimeout(() => {
          this.he = "calc(100vh - 270px)";
        }, 500);
      }
    },
  },
  created() {
    this.getScenicOptions();
  },
  methods: {
    getScenicOptions() {
      this.$http
        .get("scenic/isscenic/selectScenicList", {})
        .then(({ data: res }) => {
          if (res.msg == "success") {
            this.scenicOptions = res.data;
          }
        });
    },
    lookRecord(id, title) {
      this.title = title;
      this.lookShow = true;
      this.$nextTick(() => {
        this.$refs.lookRecord.dataForm.id = id;
        this.$refs.lookRecord.init();
      });
    },
  },
};
</script>
